package demo.hdz.testui;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;

/**
 * @author hdz
 * @date 2018/07/04
 */
public class TransparentActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transparent);

        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        //设置当前activity之外的窗口透明程度
        attributes.dimAmount = 0.5f;
        attributes.x = 0;
        attributes.y = 0;
        attributes.width = 500;
        attributes.height = 200;
        //自适应屏幕
        //attributes.height = ViewGroup.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(attributes);

        // 这个是去掉activity对窗口之外的触摸消息响应（如果不设置此选项，当前activity之外就不能点击）
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);

        Button btnExit = (Button) findViewById(R.id.btnExit);
        btnExit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                // 淡入淡出效果
                // 主题中已经设置效果
                //overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
            }
        });
        //overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
    }
}
